/**
 * SpringMVC restful 风格
 * 协议控制器，控制关于协议的一些业务逻辑操作
 * @author yanwl
 * @date 2014-09-11
 */
package com.chnbst.bstyun.controller.user;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.chnbst.bstyun.model.pojo.Agreement;
import com.chnbst.bstyun.model.pojo.Menu;
import com.chnbst.bstyun.service.AgreementService;
import com.chnbst.bstyun.service.MenuService;

@Controller
@RequestMapping("/agreement")
public class AgreementController {
	
	
	/**
	 * 注入 业务逻辑层
	 */
	@Autowired
	private AgreementService agreementService;
	@Autowired
	private MenuService menuService;
	
	/**
	 * http://xxx.com/agreement/{agreementId}
	 * get请求 返回某协议页面
	 */
	@RequestMapping(value="/{agreementId}",method=RequestMethod.GET)
	public ModelAndView service(@PathVariable Integer agreementId){
		List<Menu> menus = menuService.selectMenus();
		
		/**
		 * 查询所有的协议
		 */
		List<Agreement> agreements = agreementService.selectAgreements();
		
		/**
		 * 根据主键查询协议
		 */
		Agreement agreement = agreementService.selectAgreementByAgreementId(agreementId);
		
		ModelAndView mav = new ModelAndView();
		
		mav.addObject("menus", menus);
		mav.addObject("agreements", agreements);
		mav.addObject("agreement", agreement);
		mav.setViewName("agreement/agreement");
		return mav;
	}
}
